<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Youtube API Client</title>
</head>

<body>
<?php
/**
	Copyright (c) 2008-2009 Leandro Emanuel López <lopezlean@gmail.com> under GPL license 
	Simple Youtube api client
*/

if ( DEBUG ):
?>
<style>
pre {
	color: #000;
	background: #f0f0f0;
	padding: 1em;
}
pre.debug {
	background: #ffcc00;
	font-size: 120%;
	line-height: 140%;
	margin-top: 1em;
	overflow: auto;
	position: relative;
}
body{
	width: 100%;
}
.YTVideo{
	float:left;
	width: 50%;
}
</style>
<?php
endif;
$js = '';
function h1( $h1 ){ echo "<h1>$h1</h1>"; }
function h2( $h2 ){ echo "<h2>$h2</h2>"; }
function h3( $h3 ){ echo "<h3>$h3</h3>"; }
function p( $p ){ echo "<p>$p</p>"; }
function code( $code ){ echo "<pre class=\"code\">$code</pre>"; }

function showVideos( $videos ){
	global $js;
	foreach ($videos as $video ){
		$video->setHasSwfObject( true );
		echo "<div class=\"YTVideo\">";
		echo "{$video->information->mediaTitle}<br/>";
		echo "<img src=\"{$video->information->thumbnails[0]['url']}\" />";
		echo "<img src=\"{$video->information->thumbnails[1]['url']}\" />";
		echo "<img src=\"{$video->information->thumbnails[2]['url']}\" />";
		echo "<img src=\"{$video->information->thumbnails[3]['url']}\" />";
		echo $video.'<br/>';
		echo 'views:'. $video->statistic->viewCount.'<br/>';
		echo 'comments:'. $video->statistic->commentsCount.'<br/>';
		echo 'favorited:'. $video->statistic->favoriteCount.'<br/>';
		echo 'votes:'. $video->statistic->ratingCount.'<br/>';
		if ( $video->statistic->ratingCount > 0 )
			echo 'rating average: '. $video->statistic->ratingAverage." % from {$video->statistic->ratingMin} to {$video->statistic->ratingMax}<br/>";
		echo "</div>";
		$js .= $video->swfObjectJavascript( false );
	}
}

require_once ('include/youtube.php');

h1( 'Youtube API Client ('. VERSION .')' );
p ( 'Simple and powerful class that use the youtube\'s API' );

h2( 'Basic Usage' );
p( 'Instantiate Youtube class' );
code('require_once(\'youtube.php\')');
code('$youtube = new Youtube');
p( 'You can set the feed locale' );
code('$youtube->setFeedLocale("ES")');

$youtube = new Youtube;
$youtube->setFeedLocale("ES");

h2( 'Find in youtube feeds' );
p('Find function accept two params, the first is the feed name and the second is an array of options' );
h3("Options");
?>
<ul>
<li><b>max-results</b> 	The max-results parameter specifies the maximum number of results that should be included in the result set. This parameter works in conjunction with the start-index parameter to determine which results to return. For example, to request the second set of 10 results – i.e. results 11-20 – set the max-results parameter to 10 and the start-index parameter to 11. The default value of this parameter is 25, and the maximum value is 50. However, for displaying lists of videos, we recommend that you set the max-results parameter to 10.
</li>
<li><b>start-index</b> 	The start-index parameter specifies the index of the first matching result that should be included in the result set. This parameter uses a one-based index, meaning the first result is 1, the second result is 2 and so forth. This parameter works in conjunction with the max-results parameter to determine which results to return. For example, to request the second set of 10 results – i.e. results 11-20 – set the start-index parameter to 11 and the max-results parameter to 10.
</li>
<li><b>strict</b> 	The strict parameter can be used to instruct YouTube to reject an API request if the request contains invalid request parameters. The default API behavior is to ignore invalid request parameters. If you want YouTube to reject API requests that contain invalid parameters, set the strict parameter value to true.
</li>
<li><b>time</b>  	The time parameter, which is only supported for the top_rated, top_favorites, most_viewed, most_popular, most_discussed, most_linked and most_responded standard feeds, restricts the search to videos uploaded within the specified time. Valid values for this parameter are today (1 day), this_week (7 days), this_month (1 month) and all_time. The default value for this parameter is all_time.
</li>
</ul>
<a href="http://code.google.com/intl/en/apis/youtube/2.0/developers_guide_protocol.html#Standard_parameters">More parameters</a>

<?
code( '$videos = $youtube->find( \'mostViewed\', array( \'time\' => \'this_week\' , \'max-results\' => 2 ) );');



h3( 'Avaiable Feeds' );
code ( implode (", ", $youtube->feeds() ) );
p("The topRated, topFavorites, mostViewed, mostDiscussed, mostLinked and mostResponded standard feeds support the time parameter.");


h2( 'Search' );
code( '$videos = $youtube->search(\'guns and roses\', array( \'max-results\' => 2 ) );' );


h2( 'Download Example' );
code( '$videos = $youtube->search(\'guns and roses\', array( \'max-results\' => 2 ) );' );
code( 'foreach ( $videos as $video ):' );
code (htmlentities('	<a href="<?php echo $youtube->download($video->shortId())?>">Download <?php echo $video->title ?></a><br/>'));
code ('endforeach;');
p( 'And the results:' );
$videos = $youtube->search('guns and roses', array( 'max-results' => 2 ) );
foreach ( $videos as $video ):
?>
	<a href="<?php echo $youtube->download($video->shortId())?>">Download <?php echo $video->title ?></a><br/>
<?
endforeach;


h1( 'Examples' );
h2('Show videos function:');
code ( htmlentities ( 'function showVideos( $videos ){
	global $js;
	foreach ($videos as $video ){
		$video->setHasSwfObject( true );
		echo "<div class=\"YTVideo\">";
		echo "{$video->information->mediaTitle}<br/>";
		echo "<img src=\"{$video->information->thumbnails[0]["url"]}\" />";
		echo "<img src=\"{$video->information->thumbnails[1]["url"]}\" />";
		echo "<img src=\"{$video->information->thumbnails[2]["url"]}\" />";
		echo "<img src=\"{$video->information->thumbnails[3]["url"]}\" />";
		echo $video."<br/>";
		echo "views:". $video->statistic->viewCount."<br/>";
		echo "comments:". $video->statistic->commentsCount."<br/>";
		echo "favorited:". $video->statistic->favoriteCount."<br/>";
		echo "votes:". $video->statistic->ratingCount."<br/>";
		if ( $video->statistic->ratingCount > 0 )
			echo "rating average: ". $video->statistic->ratingAverage." % from {$video->statistic->ratingMin} to {$video->statistic->ratingMax}<br/>";
		echo "</div>";
		$js .= $video->swfObjectJavascript( false );
	}
} ' ) );
p("Then at end of the file");
code( htmlentities(
	'	<script type="text/javascript" src="js/swfobject.js"></script>
	<script type="text/javascript">
	<?php
		echo $js;
	?> 
	</script>'
) );

	h2("Most Vieweds - This week and Max Results set to 2 ");
	code ('$videos = $youtube->find(\'mostViewed\', array( \'time\' => \'this_week\' , \'max-results\' => 2 ) );');
	code ('showVideos( $videos );');

	$videos = $youtube->find('mostViewed', array( 'time' => 'this_week' , 'max-results' => 2 ) );
	showVideos( $videos );
	h2("Most Recents - Max Results set to 2 ");
	code('$videos = $youtube->find(\'mostRecent\', array( \'max-results\' => 2 ) );');
	code ('showVideos( $videos );');
	$videos = $youtube->find('mostRecent', array( 'max-results' => 2 ) );
	showVideos( $videos );
	h2("Find in User - Max Results and Start Index set to 2");
	code('$videos = $youtube->findUser(\'vivofuerte\', array( \'max-results\' => 2, \'start-index\' => 2 ) );');
	code ('showVideos( $videos );');
	$videos = $youtube->findUser('vivofuerte', array( 'max-results' => 2, 'start-index' => 2 ) );
	showVideos( $videos );

?>
	<script type="text/javascript" src="js/swfobject.js"></script>
	<script type="text/javascript">
	<?php
		echo $js;
	?> 
	</script>
</body>
</html>
